import { request } from '../../../services/request';

// 获取设备报修列表
export const getDeviceRepairListApi = async (params: any) => {
    const requestBody = {
        current: params.current || 1,
        size: params.size || 10,
        room_id_list: params.room_id_list || [],
        state_list: params.state_list || [],
        level_list: params.level_list || [],
        keyword: params.keyword || ''
    };

    // console.log('请求设备报修 - 请求数据:', JSON.stringify(requestBody));

    try {
        const response = await request('/app/appDeviceInfo/getDeviceRepairListPage', {
            method: 'POST',
            body: JSON.stringify(requestBody)
        });

        // console.log('设备报修接口返回值:', response);
        return response;
    } catch (error) {
        console.error('获取设备报修列表失败:', error);
        throw error;
    }
};

// 获取车间列表
export const getAllRoomApi = async () => {
    try {
        const response = await request('app/appCommon/getAllRoom', {
            method: 'POST',
            body: JSON.stringify({})
        });
        return response;
    } catch (error) {
        console.error('获取车间列表失败:', error);
        throw error;
    }
};

// 新增设备报修
export const saveDeviceRepairApi = async (params: any) => {
    const requestBody = {
        device_num: params.device_num || '',
        error_desc: params.error_desc || '',
        level: params.level || 3,
        report_link_list: params.report_link_list || []
    };

    // console.log('新增设备报修 - 请求数据:', JSON.stringify(requestBody));

    try {
        const response = await request('/app/appDeviceInfo/saveDeviceRepair', {
            method: 'POST',
            body: JSON.stringify(requestBody)
        });

        // console.log('新增设备报修接口返回值:', response);
        return response;
    } catch (error) {
        console.error('新增设备报修失败:', error);
        throw error;
    }
};

// 新增：获取设备报修详情
export const getDeviceRepairDetailApi = async (id: string) => {
    const requestBody = { id };
    console.log('请求设备报修详情 - 请求数据:', JSON.stringify(requestBody));
    try {
        const response = await request('/app/appDeviceInfo/getDeviceRepairDetail', {
            method: 'POST',
            body: JSON.stringify(requestBody)
        });
        console.log('设备报修详情接口返回值:', response);
        return response;
    } catch (error) {
        console.error('获取设备报修详情失败:', error);
        throw error;
    }
}; 